<template>
    <div>
        <div>
            <div style="height:40px">
                <Button type="success" @click="questionModal = true" style="float:right;color:#fff;">{{ $t('langObj.question') }}</Button>
            </div>
            <question-list v-for="(item,index) in questionListArr" :key="index" :item="item"></question-list>
        </div>
        
        <Modal
        v-model="questionModal"
        :title="$t('langObj.question')"
        width="360"
        :mask-closable="false">
        <Input type="textarea" placeholder="在此输入文字" :rows="5" v-model="content"/>
        <div slot="footer">
                <Button type="success" @click="submitResultModal">{{ $t('langObj.submit') }}</Button>
            </div>  
        </Modal>
    </div>
</template>

<script>
import questionList from '@/components/education/lists/questionList';
import { mapActions } from 'vuex';
export default {
    components:{questionList},
    data(){
        return{
            questionModal:false,
            content:"",
            questionListArr:[],
        }
    },
    methods:{
        ...mapActions(['XgetAskList','XcreateAsk']),
        submitResultModal(){
            this.XcreateAsk({
                content:this.content,
                courseId:this.$route.params.id,
                allSee:0
            }).then(res => {
                this.$Message.success("添加成功");
                this.questionModal = false;
                this.mountQuestionList();
            }).catch(err => {
                 this.$Message.error(err.response.data.message)
            })
        },
        mountQuestionList(){
            this.XgetAskList(this.$route.params.id).then(res => {
                this.questionListArr = res.data.reverse();
            })
        }
    },
    mounted(){
        this.mountQuestionList()
    }
}
</script>

<style lang="scss" scoped>

</style>

